<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
</head>
<body>
<input type="hidden" id="id" th:value="${id}">



<table id="table-user" class="layui-table" lay-filter="table-user">
    <h1 th:text="${contractName}"></h1>
    <hr>
    <span th:text="${text}"></span>
    <hr>
</table>
<script type="text/html" id="currentTableBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs data-count-show" lay-event="show">导出word文档</a>
</script>



<script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script th:inline="none">
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        //合同id
        let conId = $("#id").val();
        table.render({
            elem: '#table-user',
            url: '/contract/showConAndEmployee/'+conId,
            method:'post',
            page: true,
            limits: [1,5,10,15],
            limit: 10,
            cols: [[
                {field: 'id', title: 'id'},
                {field: 'empName', title: '员工姓名'},
                {field: 'startDate', title: '开始时间'},
                {field: 'endDate', title: '结束时间'},
                {field: 'year', title: '签订时长'},
                {title: '操作', toolbar: '#currentTableBar', align: "center",width :180}
            ]],
            toolbar:"#toolbar",
        });

        table.on('tool(table-user)',function (obj){

            if (obj.event==='show'){
                $.get("/contract/export",{"conId":obj.data.id},function(res){
                    console.log(res);
                    if(res){
                        layer.alert('导出成功！',{icon:1});
                    }else{
                        layer.alert('导出失败',{icon:2});
                    }
                });
                return false;
            }
            else if (obj.event === 'delete') {
                layer.confirm("确认删除吗？",function(index) {
                    $.post('/contract/delete',{"conId":obj.data.id},function(res){
                        if(res.data==="success"){
                            layer.msg(res.msg);
                            //重新加载表格
                            table.reload('table-user');
                        }
                    });
                    layer.close(index);
                })
            }


        })


        table.on('toolbar(table-user)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/contract/addContract',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        form.on('submit(data-search-btn)',function(data){
            var result=JSON.stringify(data.field);
            console.log(result);
            //执行搜索重载
            table.reload('table-user',{
                page:{
                    curr:1
                },
                where:{
                    contractname:data.field.contractname,
                }
            },'data');
            //阻止表单提交
            return false;
        })

    });
</script>

</body>
</html>